/**
 * pinia
 * @see https://nuxt.com/modules/pinia
 * @see https://prazdevs.github.io/pinia-plugin-persistedstate/frameworks/nuxt.html pinia 持久化存储
 */
export const useSettingStore = defineStore(
  'setting',
  () => {
    // 主题
    const colorMode = useColorMode()
    const theme = ref('system') // 默认保持和 colorMode.preference 一致
    watch(
      theme,
      (newVal) => {
        colorMode.preference = newVal
      },
      {
        immediate: true
      }
    )
    // 品牌主色
    const primaryColor = ref('#409eff')

    return {
      theme,
      primaryColor
    }
  },
  {
    persist: true
  }
)
